home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dvips / texc.lpro < prev    next >
Text File  |  1990-02-26  |  9KB  |  258 lines

  1. % The following defines procedures assumed and used by program "dvips"
  2. % and must be downloaded or sent as a header file for all TeX jobs.
  3. % Originated by Neal Holtz, Carleton University, Ottawa, Canada
  4. %      <holtz@cascade.carleton.cdn>
  5. %      June, 1985
  6. %
  7. %   Hacked by tgr, July 1987, stripped down to bare essentials,
  8. %   plus a few new commands for speed.
  9. %
  10. %   Hacked by don, December 1989, to give characters top down and to
  11. %   remove other small nuisances; merged with tgr's compression scheme
  12. %
  13. % To convert this file into a downloaded file instead of a header
  14. % file, uncomment all of the lines beginning with %-%
  15. %
  16. %   To observe available VM, uncomment the following.
  17. %   (The first ten lines define a general 'printnumber' routine.)
  18. %
  19. % /VirginMtrx 6 array currentmatrix def
  20. % /dummystring 20 string def
  21. % /numberpos 36 def
  22. % /printnumber { gsave VirginMtrx setmatrix
  23. %   /Helvetica findfont 10 scalefont setfont
  24. %   36 numberpos moveto
  25. %   /numberpos numberpos 12 add def
  26. %   dummystring cvs show
  27. %   grestore
  28. %   } bind def
  29. % /showVM { vmstatus exch sub exch pop printnumber } def
  30. % /eop-aux { showVM } def
  31. %
  32. %-%0000000             % Server loop exit password
  33. %-%serverdict begin exitserver
  34. %-%  systemdict /statusdict known
  35. %-%  {statusdict begin 9 0 3 setsccinteractive /waittimeout 300 def end}
  36. %-% if
  37.  
  38. /TeXDict 200 dict def   % define a working dictionary
  39. TeXDict begin           % start using it.
  40.  
  41. /bdf { bind def } def
  42.  
  43. % The output of dvips assumes pixel units, Resolution/inch, with
  44. % increasing y coordinates corresponding to moving DOWNWARD.
  45. % The PostScript default is big point units (bp), 72/inch, with
  46. % increasing y coordinates corresponding to moving UP; the
  47. % following routines handle conversion to dvips conventions. 
  48.  
  49. % Let the PostScript origin be (xps,yps) in dvips coordinates.
  50. /@rigin                 % -xps -yps @rigin -   establishes dvips conventions
  51.   { 72 Resolution div dup neg scale
  52.     translate
  53.   } bdf
  54.  
  55. % Here we assume the PostScript origin is at the bottom left corner
  56. % and that the paper is 11 inches high;
  57. % the dvips origin is 1 inch from top left corner;
  58. % hence if Resolution=300, we have (xps,yps)=(-300,3000). 
  59. /@letter                % setup for standard letter format
  60.   { Resolution dup -10 mul @rigin } bdf
  61.  
  62. /@landscape
  63.   { [ 0 1 -1 0 0 0 ] concat
  64.     Resolution dup @rigin } bdf
  65.  
  66. /@a4
  67.   { Resolution dup -10.6929133858 mul @rigin } bdf
  68.  
  69. /@legal
  70.   { Resolution dup -13 mul @rigin } bdf
  71.  
  72. /@manualfeed
  73.    { statusdict /manualfeed true put
  74.    } bdf
  75.  
  76.         % n @copies -   set number of copies
  77. /@copies
  78.    { /#copies exch def
  79.    } bdf
  80.  
  81. % Bitmap fonts are called fa, fb, ..., fz, f0, f1, ...; the maximum
  82. % supported by these macros is f999, but if you really go up that high
  83. % you need to increase the size of TeXDict.
  84. % The calling sequence for downloading font foo is
  85. %           /foo df chardef1 ... chardefn dfe
  86. % where each chardef is
  87. %           [<hexstring> wd ht xoff yoff dx] charno dc
  88.  
  89. /@FontMatrix [1 0 0 -1 0 0] def
  90. /@FontBBox [0 0 0 0] def
  91.  
  92. /dmystr (ZZf@@@) def       % define a place to put the new name
  93. /newname {dmystr cvn} bdf  % make it easy to get that name
  94. /df       % id df -         -- initialize a new font dictionary
  95.   { /fontname exch def
  96.     dmystr 2 fontname cvx (@@@@) cvs putinterval  % put name in template
  97.     newname 7 dict def              % allocate new font dictionary
  98.     newname load begin
  99.         /FontType 3 def
  100.     /FontMatrix @FontMatrix def
  101.     /FontBBox @FontBBox def
  102.         /BitMaps 256 array def
  103.         /BuildChar {CharBuilder} def
  104.         /Encoding IdentityEncoding def
  105.         end
  106.     fontname { /foo setfont }       %  dummy macro to be filled in
  107.        2 array copy cvx def         %  have to allocate a new one
  108.     fontname load                   %  now we change it
  109.        0 dmystr 6 string copy       %  get a copy of the font name
  110.        cvn cvx put                  %  and stick it in the dummy macro
  111.   } bdf
  112.  
  113. /dfe { newname dup load definefont setfont } bdf
  114.  
  115. % the following is the only character builder we need.  it looks up the
  116. % char data in the BitMaps array, and paints the character if possible.
  117. % char data  -- a bitmap descriptor -- is an array of length 6, of
  118. %          which the various slots are:
  119.  
  120. /ch-image {ch-data 0 get} bdf   % the hex string image
  121. /ch-width {ch-data 1 get} bdf   % the number of pixels across
  122. /ch-height {ch-data 2 get} bdf  % the number of pixels tall
  123. /ch-xoff  {ch-data 3 get} bdf   % number of pixels to right of origin
  124. /ch-yoff  {ch-data 4 get} bdf   % number of pixels below origin
  125. /ch-dx  {ch-data 5 get} bdf   % number of pixels to next character
  126.  
  127. /CharBuilder    % fontdict ch Charbuilder -     -- image one character
  128.      {save 3 1 roll exch /BitMaps get exch get /ch-data exch def
  129.       ch-data null ne
  130.       {ch-dx 0 ch-xoff ch-yoff neg
  131.        ch-xoff ch-width add ch-height ch-yoff sub
  132.        setcachedevice
  133.        ch-width ch-height true
  134.        [1 0 0 -1 -.1 ch-xoff sub ch-height ch-yoff sub .1 add]
  135. % here's the alternate code for unpacking compressed fonts
  136.      /id ch-image def                          % image data
  137.      /rw ch-width 7 add 8 idiv string def      % row, initially zero
  138.      /rc 0 def                                 % repeat count
  139.      /gp 0 def                                 % image data pointer
  140.      /cp 0 def                                 % column pointer
  141.      { rc 0 ne { rc 1 sub /rc exch def rw } { G } ifelse } imagemask
  142.    }if
  143.    restore
  144. } bdf
  145. /G { { id gp get /gp gp 1 add def
  146.   dup 18 mod exch 18 idiv pl exch get exec } loop } bdf
  147. /adv { cp add /cp exch def } bdf
  148. /chg { rw cp id gp 4 index getinterval putinterval
  149.         dup gp add /gp exch def adv } bdf
  150. /nd { /cp 0 def rw exit } bdf
  151. /lsh { rw cp 2 copy get dup 0 eq { pop 1 } { dup 255 eq { pop 254 }
  152.     { dup dup add 255 and exch 1 and or } ifelse } ifelse put 1 adv } bdf
  153. /rsh { rw cp 2 copy get dup 0 eq { pop 128 } { dup 255 eq { pop 127 }
  154.     { dup 2 idiv exch 128 and or } ifelse } ifelse put 1 adv } bdf
  155. /clr { rw cp 2 index string putinterval adv } bdf
  156. /set { rw cp fillstr 0 4 index getinterval putinterval adv } bdf
  157. /fillstr 18 string 0 1 17 { 2 copy 255 put pop } for def
  158. /pl [
  159.    { adv 1 chg } bind
  160.    { adv 1 chg nd } bind
  161.    { 1 add chg } bind
  162.    { 1 add chg nd } bind
  163.    { adv lsh } bind
  164.    { adv lsh nd } bind
  165.    { adv rsh } bind
  166.    { adv rsh nd } bind
  167.    { 1 add adv } bind
  168.    { /rc exch def nd } bind
  169.    { 1 add set } bind
  170.    { 1 add clr } bind
  171.    { adv 2 chg } bind
  172.    { adv 2 chg nd } bind
  173.    { pop nd } bind ] def
  174. % end of code for unpacking compressed fonts
  175.  
  176.                % in the following, the font-cacheing mechanism requires that
  177.                 % a name unique in the particular font be generated
  178.  
  179. /dc            % char-data ch dc -    -- define character bitmap in current font
  180.   { /ch-code exch def
  181.     /ch-data exch def
  182.     newname load /BitMaps get ch-code ch-data put
  183.   } bdf
  184.  
  185. /bop           % bop -              -- begin a brand new page
  186.   {
  187.     gsave /SaveImage save def
  188.     0 0 moveto
  189.   } bdf
  190.  
  191. /eop           % - eop -              -- end a page
  192.   { % eop-aux  % -- to observe VM usage
  193.     clear SaveImage restore
  194.     showpage grestore
  195.   } bdf
  196.  
  197. /@start         % - @start -            -- start everything
  198.   {
  199.     /Resolution exch def
  200.     /IdentityEncoding 256 array def
  201.     0 1 255 {IdentityEncoding exch 1 string dup 0 3 index put cvn put} for
  202.   } bdf
  203.  
  204. /p { show } bdf        %  the main character setting routine
  205.  
  206. /RuleMatrix [ 1 0 0 -1 -.1 -.1 ] def % things we need for rules
  207. /BlackDots 8 string def
  208. /v {                   % can't use ...fill; it makes rules too big
  209.    gsave
  210.       currentpoint translate
  211.       false RuleMatrix { BlackDots } imagemask
  212.    grestore
  213. } bdf
  214. /a { moveto } bdf    % absolute positioning
  215. /delta 0 def         % we need a variable to hold space moves
  216. %
  217. %   The next ten macros allow us to make horizontal motions that
  218. %   are within 4 of the previous horizontal motion with a single
  219. %   character.  These are typically used for spaces.
  220. %
  221. /tail { dup /delta exch def 0 rmoveto } bdf
  222. /b { exch show tail } bdf      % show and tail!
  223. /c { show delta 4 sub tail } bdf
  224. /d { show delta 3 sub tail } bdf
  225. /e { show delta 2 sub tail } bdf
  226. /f { show delta 1 sub tail } bdf
  227. /g { show delta 0 rmoveto } bdf
  228. /h { show delta 1 add tail } bdf
  229. /i { show delta 2 add tail } bdf
  230. /j { show delta 3 add tail } bdf
  231. /k { show delta 4 add tail } bdf
  232. %
  233. %   These next allow us to make small motions (-4..4) cheaply.
  234. %   Typically used for kerns.
  235. %
  236. /l { show -4 0 rmoveto } bdf
  237. /m { show -3 0 rmoveto } bdf
  238. /n { show -2 0 rmoveto } bdf
  239. /o { show -1 0 rmoveto } bdf
  240. /q { show 1 0 rmoveto } bdf
  241. /r { show 2 0 rmoveto } bdf
  242. /s { show 3 0 rmoveto } bdf
  243. /t { show 4 0 rmoveto } bdf
  244. %
  245. %   w is good for small horizontal positioning.  x is good for small
  246. %   vertical positioning.  And y is good for a print followed by a move.
  247. %
  248. /w { 0 rmoveto } bdf
  249. /x { 0 exch rmoveto } bdf
  250. /y { 3 2 roll show moveto } bdf
  251. %
  252. %   The bos and eos commands bracket sections of downloaded characters.
  253. %
  254. /bos { /section save def } bdf
  255. /eos { clear section restore } bdf
  256.  
  257. end  % revert to previous dictionary
  258.